<template>
  <div class="app">
    <!-- 头部 -->
    <div class="top_title">
      <div class="header">用户登录</div>
    </div>
    <ul class="form-box">
      <li>
        <div class="title">用户名：</div>
        <div class="content">
          <input type="text" placeholder="用户名" id="tel" v-model="userName" />
        </div>
      </li>
      <li>
        <div class="title">密码：</div>
        <div class="content">
          <input
            type="password"
            placeholder="密码"
            id="psd"
            v-model="password"
          />
        </div>
      </li>
    </ul>
    <div class="button-login">
      <button id="login" @click="userLogin">登陆</button>
    </div>
    <div class="button-register">
      <router-link to="/register"> <button>去注册</button></router-link>
    </div>
  </div>
</template>
<script>
import axios from "axios"
export default {
  data() {
    return {
      userName: "",
      password: "",
    }
  },
  methods: {
    userLogin() {
      console.log(this.userName, this.password)
      axios.defaults.baseURL = ""
      axios.defaults.withCredentials = false
      axios.defaults.headers.post["Content-Type"] = "application/json"
      axios
        .get("http://localhost:8089/login", {
          params: {
            userName: this.userName,
            password: this.password,
          },
        })
        .then((res) => {
          console.log(res)
        })
      alert("登录成功")
      // 注册成功后跳转到登录页面
      this.$router.push("/index")
    },
  },
}
</script>
<style scoped>
.app {
  width: 100%;
  height: 100%;
}
.app .top_title {
  width: 100%;
  height: 12vw;
  background-color: #0097ff;
}
.app .top_title .header {
  width: 100%;
  height: 12vw;
  background-color: #0097ff;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4.8vw;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10;
}
.app .form-box {
  width: 100%;
  /* margin-top: 12vw; */
}
.app .form-box li {
  box-sizing: border-box;
  padding: 4vw 3vw 0 3vw;
  display: flex;
  align-items: center;
}
.app .form-box li .title {
  flex: 0 0 18vw;
  font-size: 3vw;
  font-weight: 700;
  color: #666;
}
.app .form-box li .content {
  flex: 1;
}
.app .form-box li .content input {
  border: none;
  outline: none;
  width: 100%;
  height: 4vw;
  font-size: 3vw;
}
.app .button-login {
  width: 100%;
  box-sizing: border-box;
  padding: 4vw 3vw 0 3vw;
}
.app .button-login button {
  width: 100%;
  height: 10vw;
  font-size: 3.8vw;
  font-weight: 700;
  color: #fff;
  background-color: #38ca73;
  border-radius: 4px;
  border: none;
  outline: none;
}
.app .button-register {
  width: 100%;
  box-sizing: border-box;
  padding: 4vw 3vw 0 3vw;
}
.app .button-register button {
  width: 100%;
  height: 10vw;
  font-size: 3.8vw;
  font-weight: 700;
  /*与上面登陆按钮不同的只有颜色、背景色、边框不同*/
  color: #666;
  background-color: #eee;
  border: solid 1px #ddd;
  border-radius: 4px;
  border: none;
  outline: none;
}
</style>
